home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Amiga-E / E_v3.2a_extras / PdSrc / MakeKickFile.e < prev    next >
Text File  |  1992-09-02  |  4KB  |  110 lines

  1. ;/* MakeKickFile.e - Execute me to compile with Amiga E v2.1
  2. ec MakeKickFile
  3. quit
  4. */
  5. /*
  6. **      $Filename: MakeKickFile.e $
  7. **      $Release: 1.1 $
  8. **
  9. **      (C) Copyright 1991-1993 Jaba Development.
  10. **          Written by Jan van den Baard
  11. **
  12. **      Create a rom-kick file of the machine it is run on.
  13. **      It can create 256K and 512K ROM files.
  14. **
  15. **      This is a direct translation from my original C code
  16. **      and the first thing I wrote in Amiga E. Therefore it
  17. **      might not make full use of E it's special features.
  18. **      Please forgive me for that.
  19. **
  20. **      The usage is simple. You pass this program a filename
  21. **      and, if the rom size is known, it will write the ROM
  22. **      of the machine to the file. It writes the ROM, *NOT*
  23. **      a soft-kicked rom.
  24. **
  25. **      The output can be used by setcpu or skick to boot up
  26. **      a machine with the ROM file.
  27. **
  28. **      I have successfully tested it with an A1200 ROM on
  29. **      a A2500.
  30. **
  31. **      No testing has been made with a 1.2/1.3 ROM file.
  32. **      I don't have access to a 1.2/1.3 machine.
  33. **
  34. **      This really is a hack...but a hack that works!
  35. **/
  36.  
  37. MODULE  'dos/dos'
  38.  
  39. /* ROM size constants and magic cookies */
  40. CONST   SMALLROM = $00040000, SMALLMAGIC = $11114EF9,
  41.         BIGROM   = $00080000, BIGMAGIC   = $11144EF9
  42.  
  43. /* C= RomFileHeader structure */
  44. OBJECT  romfileheader
  45.     alwaysnil :  LONG       /* like it says -: always NIL */
  46.     romsize   :  LONG       /* the size of the ROM */
  47. ENDOBJECT
  48.  
  49. /* only three excpetion errors... */
  50. ENUM    ER_USAGE=1, ER_UNKNOWN, ER_IO
  51.  
  52. /* here we go... */
  53. PROC main() HANDLE
  54.     DEF outfile = NIL,
  55.         base    = NIL : PTR TO LONG,
  56.         size    = NIL,
  57.         len     = NIL,
  58.         rk, rfh       : romfileheader
  59.  
  60.     WriteF( '\e[1mMakeKickFile version 1.1 - (C) 1991-1993 Jaba Development\e[0m\n' );
  61.  
  62.     /* no args or "?" as arg then print the usage */
  63.     IF StrCmp( arg, '', 1 ) OR StrCmp( arg, '?', 2 ) THEN Raise( ER_USAGE )
  64.  
  65.     /* first try for a 512 KB ROM */
  66.     base := $00F80000
  67.  
  68.     /* if the magic cookie isn't BIGMAGIC then it must be a 256 KB ROM */
  69.     IF ( base[ 0 ] <> BIGMAGIC ) THEN base := $00FC0000
  70.  
  71.     /* let's see what ROM we are dealing with */
  72.     rk := base[ 0 ]
  73.  
  74.     SELECT rk
  75.         CASE    SMALLMAGIC; size := SMALLROM        /* 256 KB */
  76.         CASE    BIGMAGIC;   size := BIGROM          /* 512 KB */
  77.         DEFAULT;            Raise( ER_UNKNOWN )     /* unknown... */
  78.     ENDSELECT
  79.  
  80.     /* show the ROM size */
  81.     WriteF( 'ROM Size = \dKByte.\n', size / 1024 )
  82.  
  83.     /* open the kick-file */
  84.     IF ( outfile := Open( arg, MODE_NEWFILE ))
  85.         WriteF( 'Writing KickFile image...\n' )
  86.  
  87.         rfh.alwaysnil := NIL        /* set this field to NIL */
  88.         rfh.romsize   := size       /* put the ROM size here */
  89.  
  90.         len := Write( outfile, rfh, 8 ) /* write the romfileheader */
  91.         len := len + Write( outfile, base, size )   /* write the rom */
  92.  
  93.         Close( outfile ) /* close the kick-file */
  94.  
  95.         /* was the writing successfull? */
  96.         IF ( ( len <> ( size + 8 )) OR IoErr() ) THEN Raise( ER_IO )
  97.     ELSE
  98.         /* could not open the file! */
  99.         WriteF( 'Unable to open the output file!\n' )
  100.     ENDIF
  101. EXCEPT
  102.     /* exception handler for when no output name was given
  103.        or the ROM is not recognized or an IO error. */
  104.     SELECT exception
  105.         CASE    ER_USAGE;   WriteF( 'Usage: MakeKickFile <romfilename>\n' )
  106.         CASE    ER_UNKNOWN; WriteF( 'Unknown ROM! Exiting...\n' )
  107.         DEFAULT;            PrintFault( IoErr(), 'Error -' )
  108.     ENDSELECT
  109. ENDPROC IoErr()
  110.